import 'dart:async';
import 'dart:convert';
import 'dart:math';
import 'dart:io';
import 'package:app/util.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:http/http.dart' as http;
import 'package:web_socket_channel/io.dart';
import 'package:web_socket_channel/web_socket_channel.dart';
import 'dart:convert' as convert;

class RightView extends StatefulWidget{
  @override
  State<StatefulWidget> createState() => _RightView();

}


class _RightView extends State<RightView>{

  Widget rcenterWidget = _Center();
  Widget _leftWidget = _Left();
  Widget _rightWidget = _Right();

  @override
  Widget build(BuildContext context) {
    // TODO: implement build

    return Flexible(
      flex: 1,
      child: Flex(
        direction: Axis.horizontal,
        mainAxisAlignment: MainAxisAlignment.center,
        crossAxisAlignment: CrossAxisAlignment.center,
        verticalDirection: VerticalDirection.down,
        children: [
          _leftWidget,
          rcenterWidget,
          _rightWidget,

        ],
      ),
    );
  }
}

class SelectorForm{
  String title = "未选择";
  List<Map<String, dynamic>> centerData  = [];
  late WebSocketChannel channel;
  HttpClient client = HttpClient();
  bool islink = false;

  SelectorForm(){
    client.findProxy = (uri){
      return "PROXY 127.0.0.1:10809";
    };
  }

}


class _Center extends StatefulWidget {
  _Center();

  @override
  State<StatefulWidget> createState() => rcenter();
}

class rcenter extends State<_Center>{

  static SelectorForm selectorForm = SelectorForm();

  late Duration duration;
  late Timer timer;

  @override
  void didChangeDependencies() {
    super.didChangeDependencies();
    duration = Duration(seconds: 1);
    Timer.periodic(duration, (timer) {
      //1s 回调一次
      // 刷新页面
      setState(() {
          this.reassemble();
      });
    });
  }

  @override
  void dispose() {
    super.dispose();
    // 取消定时器
    timer.cancel();
  }

  @override
  void initState() {
    super.initState();

  }

  @override
  Widget build(BuildContext context) {
    return Flexible(
      flex: 1,
      child: Container(
        decoration: BoxDecoration(
          color: const Color(0xFF161A1F),
          border: Border.all(width: 1, color: Colors.black12),
        ),
        width: 1000,
        child: Scaffold(

          appBar: AppBar(
            backgroundColor: Color(0xff000000),
            title:  Text(selectorForm.title,style: const TextStyle(
              fontSize:20.0, // 文字大小
              color:Color(0xFFffffff), // 文字颜色
            ))
          ),
          floatingActionButton: Flex(
            direction: Axis.horizontal,
            children: [
              FloatingActionButton(onPressed: () {
                if(selectorForm.islink){
                    selectorForm.channel = IOWebSocketChannel.connect(Uri.parse('wss://stream.binance.com:9443/ws/'+selectorForm.title.replaceFirst('/', '').toLowerCase()+'@aggTrade'),customHttpClient: selectorForm.client);
                   selectorForm.centerData = [];
                   selectorForm.channel.stream.listen(
                        (event) {
                      print(selectorForm.centerData.length);
                      selectorForm.islink = true;
                      selectorForm.centerData.add(convert.jsonDecode(event));

                    }, //监听服务器消息
                    onError: (error) {
                    }, //连接错误时调用
                    onDone: () {
                      selectorForm.islink = false;
                    }, //关闭时调用
                    cancelOnError: true, //设置错误时取消订阅
                  );

                }else{
                  selectorForm.islink = false;
                  selectorForm.channel.sink.close();
                }
                setState(() {

                });
              },child: Text(selectorForm.islink ? '断开' : "连接"),),
              Text(selectorForm.islink ? '正在连接' : "连接断开")
            ],
          ),
          floatingActionButtonLocation: FloatingActionButtonLocation.centerDocked,
          body: Flex(
            direction: Axis.vertical,
            children: [
              Flexible(
                child: Flex(
                  direction: Axis.vertical,

                  children: [
                    Container(
                      decoration: BoxDecoration(
                        color: const Color(0xFF161A1F),
                        border: Border.all(width: 1, color: Colors.black12),
                      ),
                      child: Flex(
                          direction: Axis.horizontal,
                          children:const [
                            Flexible(child: Text("标号",style: TextStyle(
                              fontSize:15.0, // 文字大小
                              color:Color(0xFF565E69), // 文字颜色
                            ),textAlign: TextAlign.center),flex: 1,fit: FlexFit.tight,),
                            Flexible(child: Text("价格",style: TextStyle(
                              fontSize:15.0, // 文字大小
                              color:Color(0xFF565E69), // 文字颜色
                            ),textAlign: TextAlign.center),flex: 1,fit: FlexFit.tight,),
                            Flexible(child: Text("成交额",style: TextStyle(
                              fontSize:15.0, // 文字大小
                              color:Color(0xFF565E69), // 文字颜色
                            ),textAlign: TextAlign.center),flex: 1,fit: FlexFit.tight,),
                            Flexible(child: Text("时间",style: TextStyle(
                              fontSize:15.0, // 文字大小
                              color:Color(0xFF565E69), // 文字颜色
                            ),textAlign: TextAlign.center),flex: 1,fit: FlexFit.tight,),
                          ],
                      ),
                    ),
                    Flexible(
                      child:Container(
                        child: ListView(
                            children: _getListTitle(),
                            controller: ScrollController(initialScrollOffset:4) ,
                        ),
                        decoration: BoxDecoration(
                          color: const Color(0xFF161A1F),
                          border: Border.all(width: 1, color: Colors.black12),
                        ),
                      ),

                    )
                  ],
                ),
              ),
            ],
          ),
        ),
      ),
    );
  }
  List<Widget> _getListTitle(){
    List<Widget> res = [];

    int i = 0;
    for (var item in selectorForm.centerData) {
      i+=1;
      res.add(ListTile(
        title: Container(
          child: Flex(
            direction: Axis.horizontal,
            children: [
              Flexible(
                flex: 1,
                fit: FlexFit.tight,
                child: Text('$i',style: TextStyle(fontSize: 15,color:Color(0xffffffff)),),
              ),
              Flexible(
                flex: 2,
                fit: FlexFit.tight,
                child: Text(double.parse(item['p']).toString(),style: TextStyle(fontSize: 15,color:Color(0xffffffff)),),
              ),
              Flexible(
                flex: 2,
                fit: FlexFit.tight,
                child: Text((double.parse(item['p'])*double.parse(item['q'])/1000).toStringAsFixed(1)+"k",style: TextStyle(fontSize: 13,color : (item["m"] ? Color(0xff00ff00) :Color(0xffff0000))),textAlign: TextAlign.center,),
              ),
              Flexible(
                flex: 2,
                fit: FlexFit.tight,
                child: Text(DateTime.fromMillisecondsSinceEpoch(item['T']).toString(),style: TextStyle(fontSize: 13,color:Color(0xffffffff)),textAlign: TextAlign.center,),
              )
            ],
          ),
          decoration: (double.parse(item['p'])*double.parse(item['q'])/1000)>GlobalParams.form_yellow ? (
              (double.parse(item['p'])*double.parse(item['q'])/1000)>GlobalParams.form_red ? (
                  (double.parse(item['p'])*double.parse(item['q'])/1000)>GlobalParams.form_blue ?
                  (
                      (double.parse(item['p'])*double.parse(item['q'])/1000)>GlobalParams.form_wihte ?
                      BoxDecoration(color:GlobalParams.form_wihte_is ? const Color(0x3bffffff) : null):
                      BoxDecoration(color: GlobalParams.form_blue_is ? const Color(0x600048ff) : null)
                  ):
                  BoxDecoration(color: GlobalParams.form_red_is ? const Color(0x60ff0000) : null )
              ) :
              BoxDecoration(color: GlobalParams.form_yellow_is ? const Color(0x85ffd300) : null)
          ) :null,
        ),
        dense: true,
        style: ListTileStyle.list,
      ));
    }
    return res;
  }
}

class _Left extends StatefulWidget{
    _Left();

  @override
  State<StatefulWidget> createState() => _left();


}

class _left extends State<_Left>{


  late WebSocketChannel channel;
  late HttpClient client;
  late Map<String ,Map<String,dynamic>> data = {
      "USDT":{},
      "BUSD":{},
      "BTC":{}
  };
  late Map<String ,List<dynamic>> data_list = {
    "USDT":[],
    "BUSD":[],
    "BTC":[]
  };
  late bool is_2 = false;
  late bool sort = false;
  late bool sort2 = false;
  late bool islink = false;

  @override
  void dispose(){
    channel.sink.close();
    super.dispose();
  }

  @override
  void initState() {
    client = HttpClient();
    client.findProxy = (uri){
      return "PROXY 127.0.0.1:10809";
    };
    channel = IOWebSocketChannel.connect(Uri.parse('wss://stream.binance.com:9443/ws/!ticker@arr'),customHttpClient: client);
    channel.stream.listen(
            (event) {
              setState(() {
                islink = true;
                late List<dynamic> _data = convert.jsonDecode(event);
                for (var i in _data) {
                  var name = i['s'].toString();
                  for(var j in ['USDT',"BUSD","BTC"]){
                    // print(name);
                    if(name.substring(name.length-4).contains(j)){
                      i['ss'] = name.replaceFirst(j, '');
                      data[j]![name.replaceFirst(j, '')] = i;
                    }
                  }

                }
                for(var j in ['USDT',"BUSD","BTC"]){
                  data_list[j] = (data[j] as Map).values.toList();
                }
              });
        }, //监听服务器消息
        onError: (error){
          setState(() {
            islink = false;
            channel.sink.close();
          });
        }, //连接错误时调用
        onDone: (){

          setState(() {
            islink = false;
          });
        }, //关闭时调用
        cancelOnError:true, //设置错误时取消订阅
    );
    super.initState();
  }

  void _sort1(){


      (data_list['USDT'] as List).sort((a, b){
        // print(double.parse(a['q']).toString()+" "+ a['q'] +" "+double.parse(b['q']).toString()+" "+b['q']);
        if(sort ? double.parse(a['q'])<double.parse(b['q']) : double.parse(a['q'])>double.parse(b['q'])){
          return 1;
        }else{
          return 0;
        }
      });
      (data_list['BUSD'] as List).sort((a, b){
        if(sort ? double.parse(a['q'])<double.parse(b['q']) : double.parse(a['q'])>double.parse(b['q'])){
          return 1;
        }else{
          return 0;
        }
      });
      (data_list['BTC'] as List).sort((a, b){
        if(sort ? double.parse(a['q'])<double.parse(b['q']) : double.parse(a['q'])>double.parse(b['q'])){
          return 1;
        }else{
          return 0;
        }
      });
      setState(() {});
      sort = ! sort;


  }

  void _sort2(){


    (data_list['USDT'] as List).sort((a, b){

      if(sort2 ? double.parse(a['P']?.replaceFirst('%', ''))<double.parse(b['P']?.replaceFirst('%', '')) : double.parse(a['P']?.replaceFirst('%', ''))>double.parse(b['P']?.replaceFirst('%', ''))){
        return 1;
      }else{
        return 0;
      }
    });
    (data_list['BUSD'] as List).sort((a, b){
      if(sort2 ? double.parse(a['P']?.replaceFirst('%', ''))<double.parse(b['P']?.replaceFirst('%', '')) : double.parse(a['P']?.replaceFirst('%', ''))>double.parse(b['P']?.replaceFirst('%', ''))){
        return 1;
      }else{
        return 0;
      }
    });
    (data_list['BTC'] as List).sort((a, b){
      if(sort2 ? double.parse(a['P']?.replaceFirst('%', ''))<double.parse(b['P']?.replaceFirst('%', '')) : double.parse(a['P']?.replaceFirst('%', ''))>double.parse(b['P']?.replaceFirst('%', ''))){
        return 1;
      }else{
        return 0;
      }
    });
    setState(() {});
    sort2 = ! sort2;

  }

  void _link(){
      if(islink){
        channel.sink.close();
      }else {
        channel = IOWebSocketChannel.connect(Uri.parse('wss://stream.binance.com:9443/ws/!ticker@arr'),customHttpClient: client);
        channel.stream.listen(
              (event) {
            islink = true;
            late List<dynamic> _data = convert.jsonDecode(event);

              for (var i in _data) {
                var name = i['s'].toString();
                for (var j in ['USDT', "BUSD", "BTC"]) {
                  print(name);
                  if (name.substring(name.length - 4).contains(j)) {
                    i['ss'] = name.replaceFirst(j, '');
                    data[j]![name.replaceFirst(j, '')] = i;
                  }
                }
              }
              for (var j in ['USDT', "BUSD", "BTC"]) {
                data_list[j] = (data[j] as Map).values.toList();
              }

          }, //监听服务器消息
          onError: (error) {
            print(error);
          }, //连接错误时调用
          onDone: () {
            setState(() {
              islink = false;
            });
          }, //关闭时调用
          cancelOnError: true, //设置错误时取消订阅
        );
      }
  }

  @override
  Widget build(BuildContext context) {
    return Flexible(
      flex: 1,
      child: DefaultTabController(
        length: 3,
        child: Scaffold(
          backgroundColor: Color(0xff1d1b1b),
          appBar: AppBar(
            backgroundColor: Color(0xff000000),
            title: Row(
              children: const <Widget>[
                Expanded(
                  child: TabBar(
                    tabs: <Widget>[
                      Tab(text: "USDT"),
                      Tab(text: "BUSD"),
                      Tab(text: "BTC"),
                    ],
                  ),
                )
              ],
            ),
          ),
          floatingActionButton:Row(

            children: [
              Text("排序:",style: TextStyle(color: Color(0xfff9ff00),fontWeight: FontWeight.w900,fontSize: 20),),
              FloatingActionButton(onPressed: (){_sort1(); },child: const Text('成交额'),),
              FloatingActionButton(onPressed: (){_sort2(); },child: const Text('涨幅'),),
              FloatingActionButton(onPressed: _link, child: Text(islink ? "断开" : "连接"),),
              Text(islink ? "正在连接" : "连接断开" , style: const TextStyle(color: Color(
                  0xffff7900),fontWeight: FontWeight.w300,fontSize: 15),)
            ],
          ),
          floatingActionButtonLocation: FloatingActionButtonLocation.centerDocked,
          body: TabBarView(

            children: <Widget>[
              ListView(
                controller: ScrollController(initialScrollOffset:4) ,
                physics: const ScrollPhysics(),
                children: getListItem('USDT'),
              ),
              ListView(
                controller: ScrollController(initialScrollOffset:4) ,
                children: getListItem('BUSD'),
              ),
              ListView(
                controller: ScrollController() ,
                children: getListItem('BTC'),
              )
            ],
          ),
        ),
      ),
    );
  }

  List<Widget> getListItem(String type){
    List<Widget> res = [];
    data_list[type]?.forEach((value) {
        res.add(ListTile(
          title: Flex(
            direction: Axis.horizontal,
            children: [
              Flexible(
                flex: 1,
                fit: FlexFit.tight,
                child: Text(value['ss'],style: TextStyle(fontSize: 15,color:Color(0xffffffff)),),
              ),
              Flexible(
                flex: 1,
                fit: FlexFit.tight,
                child: Text(double.parse(value['c'].toString()).toString(),style: TextStyle(fontSize: 13,color:Color(0xffffffff)),textAlign: TextAlign.center,),
              )
            ],
          ),
          subtitle: Flex(
            direction: Axis.horizontal,
            children: [
              Flexible(
                flex: 2,
                fit: FlexFit.tight,
                child: Text((double.parse(value['q'])/1000).toStringAsFixed(1)+'k',style: TextStyle(fontSize: 13,color:Color(0xffffffff)),),
              ),
              Flexible(
                flex: 1,
                fit: FlexFit.tight,
                child: Text(double.parse(value['P']).toStringAsFixed(2)+"%",style: TextStyle(fontSize: 13,color:value['p']?.contains('-') ? const Color(
                    0xffff0000) : const Color(0xff0bff00)),textAlign: TextAlign.center,),
              )
            ],
          ),
          dense: true,
          style: ListTileStyle.list,
          isThreeLine: true,
          onTap: (){

            for(var i in ['USDT','BUSD',"BTC"]){
              if(value['s'].contains(i)){
                GlobalParams.type = i;
              }
            }
            GlobalParams.title = value['s'];
            print(GlobalParams.title+'@click');
            if(rcenter.selectorForm.islink){
              rcenter.selectorForm.islink = false;
              rcenter.selectorForm.channel.sink.close();
            }
            setState(() {
              rcenter.selectorForm.title = value['s'];
              rcenter.selectorForm.channel = IOWebSocketChannel.connect(Uri.parse('wss://stream.binance.com:9443/ws/'+value['s']?.replaceFirst('/', '').toLowerCase()+'@aggTrade'),customHttpClient: client);
              rcenter.selectorForm.centerData = [];
              rcenter.selectorForm.channel.stream.listen(
                (event) {
                  print(rcenter.selectorForm.centerData.length);
                  rcenter.selectorForm.islink = true;
                rcenter.selectorForm.centerData.insert(0,convert.jsonDecode(event));

                }, //监听服务器消息
                onError: (error) {
                }, //连接错误时调用
                onDone: () {
                  rcenter.selectorForm.islink = false;
                }, //关闭时调用
                cancelOnError: true, //设置错误时取消订阅
              );
            });
          },
          hoverColor: Color(0xff933893),
        ));
    });
    return res;
  }

}

class _Right extends StatefulWidget{

  _Right();

  @override
  State<StatefulWidget> createState() => _right();

}

class _right extends State<_Right>{

  bool isup = false;
  bool c1 = true;
  int q = 0;

  late Duration duration;
  late Timer timer;

  late Map<String, dynamic> data = {
    'bids':[],
    'asks':[]
  };

  @override
  void didChangeDependencies() {
    super.didChangeDependencies();
    duration = const Duration(microseconds:100);
    Timer.periodic(duration, (timer) {
      //1s 回调一次
      // 刷新页面
      try {
        () async {
          // print(rcenter.selectorForm.title );
          if (rcenter.selectorForm.title != '未选择' && q<=10) {
            q+=1;
            var client1 = HttpClient();
            client1.findProxy = (uri) {
              return "PROXY 127.0.0.1:10809";
            };
            var url = 'https://api.binance.com/api/v3/depth?limit=100&symbol=' +
                rcenter.selectorForm.title;

            HttpClientRequest request = await client1.getUrl(
                Uri.parse(url));
            request.headers.add("User-Agent",
                "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:70.0) Gecko/20100101 Firefox/70.0");
            HttpClientResponse response = await request.close();
            var result =  await response.transform(utf8.decoder).join();
            client1.close();

            reassemble();
            setState((){
              data =  convert.jsonDecode(result);
              q-=1;
            });
          }
        }();
      }catch(e){

      }
    });
  }

  @override
  void dispose() {
    super.dispose();
    // 取消定时器
    timer.cancel();
  }

  @override
  void initState() {


    super.initState();

  }

  _right();

  @override
  Widget build(BuildContext context) {
    return Flexible(
        flex: 1,
        child: Flex(
          direction: Axis.vertical,
          mainAxisAlignment: MainAxisAlignment.start,
          crossAxisAlignment: CrossAxisAlignment.start,
          verticalDirection: VerticalDirection.down,
          textDirection: TextDirection.rtl,
          mainAxisSize: MainAxisSize.max,
          children: [
            Flexible(
              child:
              Container(
                decoration: BoxDecoration(
                  color: const Color(0xFF161A1F),
                  border: Border.all(width: 1, color: Colors.black12),
                ),
                width: 1000,
                child: Flex(
                  direction: Axis.vertical,
                  verticalDirection: VerticalDirection.down,
                  children: [
                    Flexible(
                      child: Flex(
                        direction: Axis.vertical,
                        mainAxisAlignment: MainAxisAlignment.start,
                        mainAxisSize: MainAxisSize.max,
                        crossAxisAlignment: CrossAxisAlignment.stretch,
                        children: [
                           Flexible(
                            flex: 1,
                            fit: FlexFit.tight,
                            child: Text(rcenter.selectorForm.title,style: const TextStyle(
                              fontSize:20.0, // 文字大小
                              color:Color(0xFFffffff), // 文字颜色
                            ),),
                          ),
                          Flexible(
                            flex: 1,
                            fit: FlexFit.loose,
                            child: Flex(
                              direction: Axis.horizontal,
                              children:const [
                                Flexible(child: Text("标号",style: TextStyle(
                                  fontSize:15.0, // 文字大小
                                  color:Color(0xFF565E69), // 文字颜色
                                ),textAlign: TextAlign.center),flex: 1,fit: FlexFit.tight,),
                                Flexible(child: Text("价格",style: TextStyle(
                                  fontSize:15.0, // 文字大小
                                  color:Color(0xFF565E69), // 文字颜色
                                ),textAlign: TextAlign.center),flex: 1,fit: FlexFit.tight,),
                                Flexible(child: Text("成交额",style: TextStyle(
                                  fontSize:15.0, // 文字大小
                                  color:Color(0xFF565E69), // 文字颜色
                                ),textAlign: TextAlign.center),flex: 1,fit: FlexFit.tight,),
                              ],
                            ),
                          ),
                          Flexible(
                            flex: 20,
                            fit: FlexFit.loose,
                            child: Flex(direction: Axis.vertical,
                              mainAxisSize: MainAxisSize.max,
                              children: [
                                Flexible(
                                  flex: 10,
                                  fit: FlexFit.tight,
                                  child:ListView(
                                    controller: ScrollController(initialScrollOffset:4) ,
                                    physics: const ScrollPhysics(),
                                    children: InitTest(false),
                                  ),
                                ),
                                Flexible(
                                    fit: FlexFit.tight,
                                    flex: 1,
                                    child: Flex(
                                      direction: Axis.vertical,
                                      mainAxisAlignment: MainAxisAlignment.center,
                                      crossAxisAlignment:CrossAxisAlignment.center,
                                      children: [
                                        Text('111',style: TextStyle(color: isup ? Color(0xffff0000) : Color(0xff00ff00),fontWeight: FontWeight.w800,fontSize: 20),)
                                      ],
                                    )),
                                Flexible(
                                  fit: FlexFit.loose,
                                  flex: 10,
                                  child:ListView(
                                    controller: ScrollController(initialScrollOffset:4) ,
                                    physics: const ScrollPhysics(),
                                    children: InitTest(true),
                                  ),
                                )
                              ],

                            ),
                          )
                        ],
                      ),
                    ),
                  ],
                ),
              ),
            )

          ],
        )
    );
  }


  List<Widget> InitTest(bool isred){
    if(!isred){
      GlobalParams.buy20 = [];
    }else{
      GlobalParams.sell20 = [];
    }

    List<Widget> res = [];
    var j = (!isred ? 0 : 0);
    for(var i in (isred ? List.from((data['bids'] as List)).reversed : (data['asks'] as List))){
      j+= (!isred ? 1 : 1);
      var a = double.parse(i[0]);
      var b = double.parse(i[1]);
      var c = a*b;
      if(!isred){
         res.insert(0, _DataRow(j,a,b,c,false,isred),);
         if(j<=20){
           GlobalParams.buy20.add(a);
         }
      }else{
        res.add(_DataRow(j,a,b,c,false,isred),);
        if(j<=20){
            GlobalParams.sell20.add(a);

        }
      }


    }

    return res;
  }
}



class _DataRow extends StatelessWidget{

  int index;
  double p;
  double num;
  double sump;
  bool highlight;
  bool is_buy;

  _DataRow(this.index,this.p,this.num,this.sump,this.highlight,this.is_buy);

  @override
  Widget build(BuildContext context) {
    return Container(
      decoration: sump>GlobalParams.pankou_yellow ? (
          sump>GlobalParams.pankou_red ? (
              sump>GlobalParams.pankou_blue?
              (
                  sump>GlobalParams.pankou_wihte ?
                  BoxDecoration(color:  GlobalParams.pankou_wihte_is ? const Color(0x3bffffff) : null):
                  BoxDecoration(color: GlobalParams.pankou_blue_is ? const Color(0x600048ff) : null)
              ):
              BoxDecoration(color:GlobalParams.pankou_red_is ? const Color(0x60ff0000) : null)
          ) :
          BoxDecoration(color:GlobalParams.pankou_yellow_is ? const Color(0x85ffd300) : null)
      ) :null,
        child: Flex(
          direction: Axis.horizontal,
          children:[
            Flexible(child: Text("$index",style: const TextStyle(
              fontSize:15.0, // 文字大小
              color:Color(0xFF914DFD), // 文字颜色
            ),textAlign: TextAlign.center),flex: 1,fit: FlexFit.tight,),
            Flexible(child: Text(double.parse(p.toString()).toString(),style: TextStyle(
              fontSize:15.0, // 文字大小
              color:(is_buy ? const Color(0xFF1DFD13) :const Color(0xFFEB435B)), // 文字颜色
            ),textAlign: TextAlign.center),flex: 1,fit: FlexFit.tight,),
            Flexible(child: Text(sump.toStringAsFixed(1)+'k',style: const TextStyle(
              fontSize:15.0, // 文字大小
              color:Color(0xFFBEC4CE), // 文字颜色
            ),textAlign: TextAlign.center),flex: 1,fit: FlexFit.tight,),
          ],
        ),
    );
  }
}
